﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using GD.ModelContest.Common;
using GD.ModelContest.Model;
using GD.ModelContest.Service;


namespace GD.ModelContest.Web
{
    public partial class NewList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBind_NewsList(0);
            }
        }

        protected void DataBind_NewsList(int recordcount)
        {

            if (recordcount == 0)
            {
                this.AspNetPager_Content.CurrentPageIndex = 1;
            }

            int count = recordcount;
            int pageIndex = this.AspNetPager_Content.CurrentPageIndex;
            int pageSize = this.AspNetPager_Content.PageSize;
            string newsType = Request.QueryString["newsType"];
            this.rptNewsList.DataSource = ServiceLocator.INewsService.GetNewsCollection(int.Parse(newsType), pageIndex, pageSize, ref count);
            this.rptNewsList.DataBind();
            this.AspNetPager_Content.RecordCount = count;
        }

        protected void rptNewsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                mc_news mcNews = (mc_news)e.Item.DataItem;
                Literal ltNum = (Literal)e.Item.FindControl("ltNum");
                ltNum.Text = (e.Item.ItemIndex + 1).ToString();
                HyperLink hlNewsTitle = (HyperLink)e.Item.FindControl("hlNewsTitle");
                hlNewsTitle.Text = mcNews.title;
                hlNewsTitle.NavigateUrl = string.Format("NewsView.aspx?NewsId={0}", mcNews.newsId);
            }
        }

        protected void AspNetPager_Content_PageChanged(object sender, EventArgs e)
        {
            DataBind_NewsList(this.AspNetPager_Content.RecordCount);
        }


    }
}
